package com.snl.micro.blog.article.controller;

import com.snl.micro.blog.article.base.ScheThread;
import com.snl.micro.blog.article.pojo.enmu.Theme;
import com.snl.micro.blog.article.service.ArticleService;
import com.snl.micro.blog.common.base.pager.Pager;
import com.snl.micro.blog.common.param.ArticleSaveParam;
import com.snl.micro.blog.common.protocol.ResponseResult;
import com.snl.micro.blog.common.query.ArticleQueryParam;
import com.snl.micro.blog.common.query.TagQuery;
import com.snl.micro.blog.common.vo.ArticleVo;
import com.snl.micro.blog.common.vo.TagVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.BlockingQueue;

@Slf4j
@RestController
@RequestMapping("/v1/article/")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @Autowired
    private ScheThread scheThread;

    @Value("${server.port}")
    private String port;

    @GetMapping("hello")
    public String hello() {
        return "你好来自[%s]端口的问候".formatted(port);
    }

    @GetMapping("query")
    public ResponseResult<Pager<List<ArticleVo>>> query(ArticleQueryParam queryParam) {
        log.debug("控制器入参:{}",queryParam);
        Pager<List<ArticleVo>> pager = articleService.query(queryParam);
        return ResponseResult.success(pager);
    }

    @GetMapping("count")
    public ResponseResult<BlockingQueue<Integer>> count() {
        return ResponseResult.success(this.scheThread.getThemesCount());
    }

    @GetMapping("tags")
    public ResponseResult<List<TagVo>> tag(TagQuery query) {
        log.debug("标签查询参数:{}",query);
        List<TagVo> tags = this.scheThread.getTags(query);
        return ResponseResult.success(tags);
    }


    @PostMapping("save")
    public ResponseResult save(ArticleSaveParam param) {
        //调用业务层参数
        log.debug("这是一个保存参数,{}",param);
        articleService.save(param);
        return ResponseResult.success(null);
    }



}
